package input;

import instance.Instance;
import instance.InstanceEj1;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;

public class Problem1Input implements Input {

	
	
	private String inputFile;
	private List<Instance> instances;
	
	public Problem1Input(String inputFile) {
		this.inputFile = inputFile;

	}
    //nos guardamos todas las instancias del archivo de entrada para procesarlos de a uno
	@Override
	public void readFile() throws Exception {
				
		BufferedReader bufferedReader = new BufferedReader(new FileReader(
				new File(inputFile)));

		instances = new ArrayList<Instance>();

		while (bufferedReader.ready()) {
			Instance instance =  readInstance(bufferedReader);
			instances.add( instance);
		}
			
		bufferedReader.close();		
	}
	@Override
	public List<Instance> getInstances() {
	
		return instances;
	}
	
	@Override
	public Instance readInstance(BufferedReader bufferedReader)
			throws Exception {
		int capacidad =0;
		int energia =0;
		String line = bufferedReader.readLine();
		
		StringTokenizer tokens = new StringTokenizer(line);
		//leemos primer linea
			capacidad =Integer.parseInt(tokens.nextToken().trim());
			energia =Integer.parseInt(tokens.nextToken().trim());	
		
		//leemos segunda linea personas por pisos
			
			Vector<Integer> list_personas = new Vector<Integer>();
			line = bufferedReader.readLine();
			tokens = new StringTokenizer(line);
			
			while(tokens.hasMoreTokens()){
				list_personas.add(Integer.parseInt(tokens.nextToken().trim()));	
				
			}	
			
			Instance instance = new InstanceEj1(capacidad,energia,list_personas);
			return instance;
		
     	}
	
}
